<?php
require_once ('../configs/config.inc.php');
require_once ('../libraries/core/DataAccess.php');
require_once ('../libraries/core/models/systemusersModel.php');

$username=$_POST['login'];
$userpassword=$_POST['password'];
if(is_null($username) || $username=="") exit ( '{"Result":"false","Msg":"用户名不能为空"}');
if(is_null($userpassword)||$userpassword=="") exit( '{"Result":"false","Msg":"密码不能为空"}');

$dao=new DataAccess($dbhost, $dbuser, $dbpasswd, $dbname);
$usermodel=new systemusersModel($dao); 

$model =$usermodel->executeModel($username);
//print_r($model);
if(count($model)==0){
    exit('{"Result":"false","Msg":"用户名不存在"}');
}
else{
    if(strtolower($model[0]["Password"])!=strtolower(substr(md5($userpassword),8,16)))    {
        exit('{"Result":"false","Msg":"密码不正确"}');
    }
    else    {
        setcookie("AdminCookie", $username); 
        exit('{"Result":"true","Msg":"登录成功"}');
    }
}

//if($username!="admin")    echo '{"Result":"false","Msg":"用户名不正确"}';
//if($userpassword!="admin") echo '{"Result":"false","Msg":"密码不正确"}';
//else{
    //setcookie("AdminCookie", $username); 

    //echo '{"Result":"true","Msg":"登录成功"}';
//}

?>
